from fastapi import APIRouter

from app.database.postgre import SessionDep
from app.models.system_boards import (SystemBoardsListParams, CreateSystemBoardJSON, DeleteSystemBoardJSON,
                                      BatchDeleteBoardsJSON)
from app.services import accounts, system_boards
from app.models import responses

router = APIRouter(
    prefix='/api/v1/system_boards',
    tags=['backend', 'system_boards']
)


@router.get('/list')
async def system_boards_list(
        account: accounts.LoggedInAccount,
        query_params: SystemBoardsListParams,
        session: SessionDep):
    response = await system_boards.get_system_boards_list(account, query_params, session)
    return response


@router.post('/create')
async def create_system_board(
        account: accounts.LoggedInAccount,
        json_data: CreateSystemBoardJSON,
        session: SessionDep):
    if not account.has_admin_permission:
        return responses.Response202()

    response = await system_boards.create_system_board(account, json_data, session)
    return response


@router.post('/delete')
async def delete_system_board(
        account: accounts.LoggedInAccount,
        json_data: DeleteSystemBoardJSON,
        session: SessionDep):
    if not account.has_admin_permission:
        return responses.Response202()

    response = await system_boards.delete_board_by_id(account, json_data, session)
    return response


@router.post('/batch_delete')
async def delete_system_boards(
        account: accounts.LoggedInAccount,
        json_data: BatchDeleteBoardsJSON,
        session: SessionDep):
    if not account.has_admin_permission:
        return responses.Response202()

    response = await system_boards.delete_board_by_ids(account, json_data, session)
    return response


@router.post('/clear')
async def clear_all_system_boards(
        account: accounts.LoggedInAccount,
        session: SessionDep):
    if not account.has_admin_permission:
        return responses.Response202()

    response = await system_boards.clear_all_system_boards(account, session)
    return response
